# Maintainer: Antoine Martin <totaam@xpra.org>

_realname=libyuv
pkgbase="mingw-w64-${_realname}-git"
pkgname=(${MINGW_PACKAGE_PREFIX}-${_realname}-git)
provides=(${MINGW_PACKAGE_PREFIX}-${_realname})
conflics=(${MINGW_PACKAGE_PREFIX}-${_realname})
pkgver=1724.r7ce50764
pkgrel=1
pkgdesc="YUV conversion and scaling library"
arch=("any")
url="https://chromium.googlesource.com/libyuv/libyuv"
license=('BSD')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-cmake")
#this is the real upstream, but git checkout timesout at the moment:
#source=("${_realname}::git+https://chromium.googlesource.com/${_realname}/${_realname}"
#so we use a github mirror instead:
source=("${_realname}::git+https://github.com/lemenkov/${_realname}"
        "libyuv.pc"
        "libyuv-nojpeg.patch"
        "cmake-mingw.patch")
options=('strip' 'staticlibs')
sha256sums=('SKIP'
            '86b8cbaadaea129775ebfa2d69f7b5e7d277c39b48377966da276a46a5bb2aa8'
            '1fac09a44d5ef663478d951c4ed31bb335d5e97dc8345ffbd5ad4d07766d040c'
            '4f08ebd0647ea4873db70042334e2ef19734ddf9c7b8b1dca70b633b89e405ef')

pkgver() {
  cd "${srcdir}/${_realname}"
  VERSION=$(cat include/libyuv/version.h | grep "#define LIBYUV_VERSION" | awk '{print $3}')
  REVISION=$(git rev-parse --short HEAD)
  echo "${VERSION}.r${REVISION}"
}

prepare() {
  cd "${srcdir}/${_realname}"
  patch -p1 -i "$srcdir"/libyuv-nojpeg.patch
  patch -p1 -i "$srcdir"/cmake-mingw.patch
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd ${srcdir}/build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake -Wno-dev \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ../${_realname}
  echo "cmake done"
  make
}

package() {
  cd build-${MINGW_CHOST}
  make DESTDIR="${pkgdir}" install
  mkdir -p ${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/
  install -m644 ../libyuv.pc "${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/"
  install -Dm644 ${srcdir}/${_realname}/LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
